<?php
namespace app\admin\model;

use app\model\Base;

class UserWalletApply extends Base
{
    public function userWalletApplyUserBank()
    {
//        return $this->hasOne(UserBank::class, 'id', 'user_bank_id')
//            ->bind([
//                'real_name',
//                'no',
//                'bank_name',
//                'card_no',
//            ]);
    }

    public function getApplyTypeFormatAttr($value, $data)
    {
        return Base::$applyTypeArray[$data['apply_type']];
    }

    public function getApplyInfoFormatAttr($value, $data)
    {
//        $array = json_decode($data['apply_info'], true);
//        return $array;
        $array = [];
        if($data['apply_type'] == 'bank')
        {
            $array = [
                '银行名称：' . $data['bank_name'],
                '账号名称：' . $data['bank_account_name'],
                '卡号：' . $data['bank_card_no']

            ];
        }elseif ($data['apply_type'] == 'alipay'){
            $array = [
                '支付宝账号：' . $data['alipay_account'],
                '支付宝实名：' . $data['alipay_real_name'],
            ];
        }
        return $array;
    }

    //
//    public function getRealNameFormatAttr($value, $data)
//    {
//        $array = json_decode($data['apply_info'], true);
//        return $array;
//    }
//    public function getCardNoFormatAttr($value, $data)
//    {
//        $array = json_decode($data['apply_info'], true);
//        return $array;
//    }
//    public function getBankNameFormatAttr($value, $data)
//    {
//        $array = json_decode($data['apply_info'], true);
//        return $array;
//    }
    public function getBankNoFormatAttr($value, $data)
    {
//        {"bankAccountName":"尹登松","bankName":"中国银行福州东部新城支行","bankCard":"6217866400003650180"}
        $no = '';
        $array = json_decode($data['apply_info'], true);
        if($array['bankName']){
            $bankName = $array['bankName'];
            $no = Bank::whereLike('guard_name', $bankName)->value('no');
        }
        return $no;
    }
    public function getInfoFormatAttr($value, $data)
    {
//        {"bankAccountName":"尹登松","bankName":"中国银行福州东部新城支行","bankCard":"6217866400003650180"}
        $newArr = [
            'bankAccountName'=>'',
            'bankName'=>'',
            'bankCard'=>'',
            'bankNo'=>''
        ];
        $array = json_decode($data['apply_info'], true);
        if(isset($array['bankAccountName'])){
            $newArr['bankAccountName'] = $array['bankAccountName'];
        }
        if($array['bankName']){
            $newArr['bankName'] = $array['bankName'];
        }
        if($array['bankCard']){
            $newArr['bankCard'] = $array['bankCard'];
        }
        if($array['bankName']){
            $bankName = $array['bankName'];
            $newArr['bankNo'] = Bank::where('guard_name', 'like', '%' . $bankName . '%')->value('no');
        }
        return $newArr;
    }
    public function getContentFormatAttr($value, $data)
    {
        return '清退';
    }
    public function getMoneyFormatAttr($value, $data)
    {
        return 1;
    }
}